package com.qly.redis.server.controller;

import com.qly.redis.server.entity.UserEntity;
import com.qly.redis.server.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by Andy ye on 2018/8/3.
 */

@RestController
@RequestMapping(value = "/user")
public class UserController {

    @Autowired
    UserService userService;

    public static final String NAME = "yeqing";
    public static final String PASSWORD = "123456";
    public static final String KEY = "user";
    public static final String HASH_KEY = "1";

    @RequestMapping("/add")
    public String addUser() {

        UserEntity user = new UserEntity();
        user.setName(NAME);
        user.setPassword(PASSWORD);
        userService.save(KEY, HASH_KEY, user);

        return "新增User成功，请查看Redis缓存";

    }

    @RequestMapping("/get_by_key")
    public UserEntity getUserByKey() {

        UserEntity user = userService.getBykey(KEY, HASH_KEY);
        return user;

    }

}
